<template>
	<view class="content">

		<view class="module-name">选择成员</view>
		<view class="module-wrapper">
			<view class="module-box">
				<view class="item-title item-titles1">班级</view>
				<view class="item-box">
					<checkbox-group class="check-wrapper" v-for="(item,index) in grade" :key="index" @change="checkboxGradeChange($event,item,index)">
						<view class="grade-item">
							<label>
								<!-- {{String(item.id)}} -->
								<checkbox class="check-box" :value="String(item.id)" :checked="item.select>0?true:item.checked"
									backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff" activeBorderColor="#"
									iconColor="#FFFFFF"/>
							</label>
							<!-- {{student}} -->
							<!-- {{item.grade_id}}, -->
							<view class="item-name" @tap="handleSelecteStudent(item.id,item.grade_id)">
								{{item.grade_name}}

								<!-- (<text v-if="item.id==item.id">{{item.select}}</text>/{{item.studeentNum}}) -->
								(<text>{{item.select}}</text>/{{item.studeentNum}})
							</view>
						</view>
					</checkbox-group>
				</view>
			</view>
		</view>

		<view class="module-name">作业设置</view>
		<view class="module-wrapper">
			<view class="module-box">
				<view class="item-title">名称</view>
				<view class="item-box">
					<input class="uni-input" placeholder="请输入" v-model="name"
						placeholder-style="color: rgba(199, 202, 211, 1); font-size: 28rpx;" />
				</view>
			</view>


			<view class="module-box">
				<view class="item-title item-titles1">作业模式</view>
				<view class="item-box2">

					<view class="item-name" @click="toggle('bottom')" v-if="xuanz_moshi=='课后作业'">课后作业</view>
<!--					<view class="item-name" @click="toggle('bottom')" v-if="xuanz_moshi=='课堂教学'">课堂教学</view>-->
					<view class="item-name" @click="toggle('bottom')" v-if="xuanz_moshi=='机房考试'">机房考试</view>
					<!-- <view class="item-name" @click="toggle('bottom')" v-else>请选择作业模式</view> -->

					<uni-popup ref="popup" background-color="#fff" borderRadius="10rpx 10rpx 0rpx 0rpx " @change="change" :animation="xuanz_kt" style="border-radius: 5rpx 5rpx 0rpx 0rpx;">
						<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }" >
							<view v-for="(item,index) in zyms" :key="index" @click="xuanzde(item)"
								style=" text-align: center;  border-bottom: 1rpx solid #FBFBFB; height: 150rpx; ">
								<view style="margin-top: 10rpx;">
									<view style="line-height: 50rpx; color: #393939;">{{item.name}}</view>
									<view style="line-height: 50rpx; color: #BFBFBF; font-size: 25rpx;">{{item.test}}</view>
								</view>

							</view>
							
							<view class="submit-buttons" @click="close">
								取消
							</view>
							<!-- <text class="text">popup 内容</text> -->


						</view>
					</uni-popup>

					<view v-if="xuanz_moshi=='机房考试'">


						<view class="item-option">
							<checkbox-group @change="checkboxAnswerChange_fenshu">
								<label>
									<checkbox class="check-box" value="answer" :checked="isAnswer_fenshu"
										backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff" activeBorderColor="#"
										iconColor="#FFFFFF" />
								</label>
							</checkbox-group>
							<view class="item-name">学生提交可查看分数</view>
						</view>
						<view class="item-option">
							<checkbox-group @change="checkboxAnswerChange_bukeckfs">
								<label>
									<checkbox class="check-box" value="answer" :checked="isAnswer_bukeckfs"
										backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff" activeBorderColor="#"
										iconColor="#FFFFFF" />
								</label>
							</checkbox-group>
							<view class=""><text style=" word-wrap: break-word; word-break: break-all;">
									学生不可查看分数答案(截止后也不可看)</text></view>
						</view>

					</view>


					<view v-if="xuanz_moshi=='课后作业'">
						<view class="item-tags">
							<view :class="{selectedWork: workType === 0}" class="tag-text"
								@tap="handleSwitchWorkType(0)">练习
							</view>
							<view :class="{selectedWork: workType === 1}" class="tag-text"
								@tap="handleSwitchWorkType(1)">测试
							</view>
						</view>


						<view v-if="workType==0&&xuanz_moshi=='课后作业'">

							<view class="item-desc">学生可以多次答题，系统显示最高分</view>
							<view class="item-option">
								<checkbox-group @change="checkboxDetailChange">
									<label>
										<checkbox class="check-box" value="detail" :checked="isDetail"
											backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff"
											activeBorderColor="#" iconColor="#FFFFFF" />
									</label>
								</checkbox-group>
								<view class="item-name">学生提交后可查看详情</view>
							</view>

							<view class="item-option">
								<checkbox-group @change="checkboxAnswerChange">
									<label>
										<checkbox class="check-box" value="answer" :checked="isAnswer"
											backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff"
											activeBorderColor="#" iconColor="#FFFFFF" />
									</label>
								</checkbox-group>
								<view class="item-name">截止查看小题答案</view>
							</view>

							<view class="item-option">
								<checkbox-group @change="checkboxLimitChange">
									<label>
										<checkbox class="check-box" value="limit" :checked="isLimit"
											backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff"
											activeBorderColor="#" iconColor="#FFFFFF" />
									</label>
								</checkbox-group>
								<view class="item-condition">
									<view class="item-name">低于满分
										<input class="limit-input" type="number" placeholder="50"
											v-model="percentage" />% 则自动退回
									</view>
									<view class="item-name">低于满分
										<input class="limit-input" type="number" placeholder="2"
											v-model="frequency" />次不再退回
									</view>
								</view>
							</view>
						</view>
						<view v-if="workType==1&&xuanz_moshi=='课后作业'">

							<view class="item-desc">学生可以多只能答题一次</view>
							<view class="item-option">
								<checkbox-group @change="checkboxDetailChange">
									<label>
										<checkbox class="check-box" value="detail" :checked="isDetail"
											backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff"
											activeBorderColor="#" iconColor="#FFFFFF" />
									</label>
								</checkbox-group>
								<view class="item-name">学生提交后可查看详情</view>
							</view>

							<view class="item-option">
								<checkbox-group @change="checkboxAnswerChange">
									<label>
										<checkbox class="check-box" value="answer" :checked="isAnswer"
											backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff"
											activeBorderColor="#" iconColor="#FFFFFF" />
									</label>
								</checkbox-group>
								<view class="item-name">截止查看小题答案</view>
							</view>




							<view class="item-option">
								<checkbox-group @change="checkboxAnswerChange_fenshu">
									<label>
										<checkbox class="check-box" value="answer" :checked="isAnswer_fenshu"
											backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff"
											activeBorderColor="#" iconColor="#FFFFFF" />
									</label>
								</checkbox-group>
								<view class="item-name">学生提交可查看分数</view>
							</view>
							<view class="item-option">
								<checkbox-group @change="checkboxAnswerChange_bukeckfs">
									<label>
										<checkbox class="check-box" value="answer" :checked="isAnswer_bukeckfs"
											backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff"
											activeBorderColor="#" iconColor="#FFFFFF" />
									</label>
								</checkbox-group>
								<view class="">学生不可查看分数答案(截止后也不可看)</view>
							</view>
							<view class="item-option">
								<checkbox-group @change="checkboxAnswerChange_bujiao">
									<label>
										<checkbox class="check-box" value="answer" :checked="isAnswer_bujiao"
											backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff"
											activeBorderColor="#" iconColor="#FFFFFF" />
									</label>
								</checkbox-group>
								<view class="item-name">截止时间后学生可补交</view>
							</view>






							<view class="item-option">
								<checkbox-group @change="checkboxLimitChange">
									<label>
										<checkbox class="check-box" value="limit" :checked="isLimit"
											backgroundColor="#F7F8FA" activeBackgroundColor="#2979ff"
											activeBorderColor="#" iconColor="#FFFFFF" />
									</label>
								</checkbox-group>
								<view class="item-condition">
									<view class="item-name">低于满分
										<input class="limit-input" type="number" placeholder="50"
											v-model="percentage" />% 则自动退回
									</view>
									<view class="item-name">低于满分
										<input class="limit-input" type="number" placeholder="2"
											v-model="frequency" />次不再退回
									</view>
								</view>
							</view>
						</view>
					</view>





				</view>
			</view>

			<view class="module-box">
				<view class="item-title">截止时间</view>
				<view class="item-box">
					<uni-datetime-picker v-model="deadlinetime" :border="false" :clear-icon="false"
						:hide-second="true" :isteshu="true"/>

					<radio-group class="radio-group" @change="radioChange">
						<label class="uni-list-cell">
							<view>
								<radio value="0" :checked="endTimeType === 0" />
							</view>
							<view>当天</view>
						</label>
						<label class="uni-list-cell">
							<view>
								<radio value="1" :checked="endTimeType === 1" />
							</view>
							<view>1天</view>
						</label>
						<label class="uni-list-cell">
							<view>
								<radio value="2" :checked="endTimeType === 1" />
							</view>
							<view>2天</view>
						</label>
					</radio-group>
				</view>
			</view>

			<view class="module-box">
				<view class="item-title">定时布置</view>
				<view class="item-box">
					<checkbox-group @change="checkboxChange">
						<label>
							<checkbox class="check-box" value="settime" :checked="dingshifabu" backgroundColor="#F7F8FA"
								activeBackgroundColor="#2979ff" activeBorderColor="#" iconColor="#FFFFFF" />
						</label>
					</checkbox-group>
					<uni-datetime-picker v-model="startTime" :border="false" :clear-icon="false" hide-second="true"  :isteshu="true"/>
				</view>
			</view>

			<!-- <view class="module-box">
				<view class="item-title">作业内容</view>
				<view class="item-box"  v-for="(item,index) in xuanzhede" :key="index" style="width: 100%;">
					<checkbox-group @change="checkboxWorkChange">
						<label>
							<checkbox disabled class="check-box" value="work" :checked="true" backgroundColor="#F7F8FA"
								activeBackgroundColor="#2979ff" activeBorderColor="#" iconColor="#FFFFFF" />
						</label>
					</checkbox-group>
					
					<text>{{item.resourceName}}</text>
					
				</view>
			</view> -->
			<view  style="width: 90%;margin: 20px auto;" class="zuoyeneirong">
				<view class="item-title item-titles">作业内容</view>
				<view style="display: flex;flex-direction: column;">
					<view v-for="(item,index) in xuanzhede" :key="index"
					      style="display: flex;  line-height:60rpx; justify-content: flex-start;">
						<checkbox-group @change="checkboxWorkChange">
							<label>
								<checkbox disabled class="check-box" value="work" :checked="true" backgroundColor="#F7F8FA"
								          activeBackgroundColor="#2979ff" activeBorderColor="#" iconColor="#FFFFFF" />
							</label>
						</checkbox-group>
						<text>{{item.resourceName}}</text>
					</view>
				</view>
			
			</view>
			<view style="width: 90%;margin: 10px auto;">
				<view class="item-title">作业留言</view>
				<view class="item-box" style="margin-top: 10px;margin-bottom: 10px;">
					<input class="uni-input" placeholder="请输入" v-model="message"
					       placeholder-style="color: rgba(199, 202, 211, 1); font-size: 28rpx;" />
				</view>
			</view>
		</view>

		<view class="submit-button" @tap="handleSubmitWork">
			确认发布
		</view>
	</view>
</template>

<script>
	function getEndOfDayTimestamp(d = 0) {
		const now = new Date();
		const year = now.getFullYear();
		const month = now.getMonth();
		const day = now.getDate() + d * 1;
		const endOfDay = new Date(year, month, day, 23, 59, 59);
		const timestamp = endOfDay.getTime();
		return timestamp;
	}
	function getNowOfDayTimestamp(d = 0) {
		const now            = new Date();
		const year           = now.getFullYear();
		const month          = now.getMonth();
		const day            = now.getDate() + d * 1;
		const hour           = now.getHours();
		const miutines       = now.getMinutes();
		const seconds        = now.getSeconds();
		const startOfDay     = new Date(year, month, day, hour, miutines, seconds);
		const starttimestamp = startOfDay.getTime();
		
		return starttimestamp;
	}
	export default {
		data() {
			return {
				message:"",
				xuanzhede: [],
				student: [],
				show: false, // 控制弹框显示的变量
				xuanz_kt: false,
				list: ['选项1', '选项2', '选项3'], // 弹框中的列表数据
				title: 'Hello',
				zyms: [{
						name: '课后作业',
						test: '课前备课，课堂教学，学生通过答题器或机房电脑随堂客互动',
						id:"1"
					},
					// {
					// 	name: '课堂教学',
					// 	test: '布置课后日常作业，分练和测两种作业模式',
					// id:"2"
					// },
					{
						name: '机房考试',
						test: '学生只能在机房答题，截止时间后可在APP中查看答案',
						id:"3"
					}
				],
				xuanz_moshi: '课后作业',
				grade: [],
				name: '',
				workType: 0,
				isDetail: true, //学生提交后可查看详情
				isAnswer: true, //截止查看小题答案
				isLimit: false, //低于满分
				isAnswer_bukeckfs: false, //学生不可查看分数答案(截止后也不可看)
				dingshifabu: false, //定时发布
				endTimeType: 0,
				deadlinetime: "",
				startTime: "",
				xuanzhede_bj: [],
				operation: '1', //作业模式：1课后作业 2机房考试 3课堂教学 4打卡
				typesf: 1,
				checkinfo: 1,
				checkanswer: 1,
				checkscore: 0,
				checksw: 0,
				repair: 0,
				lowfullbi: '',
				lowfullci: 1,
				percentage: 50,
				frequency: 2,
				timing: '',
				tabarTitle:''
			}
		},
		onLoad(option) {
			this.xuanzhede = uni.getStorageSync('xuanzhede') || []; ///从本地缓存中同步移除指定key的数据
			console.log("===this.xuanzhede",this.xuanzhede)
			this.tabarTitle = option.type
			if(this.tabarTitle == '听说'){
				this.ptype = 1;
			}
			if(this.tabarTitle == '听力'){
				this.ptype = 2;
			}
			if(this.tabarTitle == '跟读'){
				this.ptype = 3;
			}
			if(this.tabarTitle == '笔试'){
				this.ptype = 4;
			}
			if(this.tabarTitle == '音标'){
				this.ptype = 5;
			}
			if(this.tabarTitle == '典范'){
				this.ptype = 6;
			}
			if(this.tabarTitle == '新概念'){
				this.ptype = 7;
			}
			if(this.tabarTitle == '黑布林'){
				this.ptype = 8;
			}
			if(this.tabarTitle == '教材同步'){
				this.ptype = 9;
			}
			console.log("===this.xuanzhede1111")
			this.banji()
		},
		onShow() {
			this.shuaxinGrade()
		},
		onUnload() {
			// 处理页面卸载的逻辑
			uni.removeStorageSync('xuanzhede_bj');
			uni.removeStorageSync('grade');
			//console.log('页面已经卸载');
		},
		onHide() {
			// uni.removeStorageSync('xuanzhede_bj');
			// uni.removeStorageSync('grade');
			// 处理页面隐藏的逻辑
			//console.log('页面已经隐藏');

		},
		mounted() {
			setTimeout(() => {
				this.deadlinetime = getEndOfDayTimestamp();
				this.startTime = getNowOfDayTimestamp();
			}, 100)
		},
		methods: {
			shuaxinGrade(){
				this.xuanzhede_bj = uni.getStorageSync('xuanzhede_bj') || []; ///从本地缓存中同步移除指定key的数据
				setTimeout(()=>{
					this.grade = uni.getStorageSync('grade')|| [];
					this.grade.forEach((item, index) => {
						if(this.xuanzhede_bj.length>0){
							this.xuanzhede_bj.forEach((banjiItem,index)=>{
								if(banjiItem.id == item.id ){
									Object.assign(item, {
										checked: true,
										id:banjiItem.id,
										uid:banjiItem.uid,
										select: banjiItem.uid.length
									})
									console.log(banjiItem.uid.length,"-=----",item)
								}else{
									Object.assign(item, {
										checked: false,
										select: 0
									})
								}
							})
						}else{
							Object.assign(item, {
								checked: false,
								select: 0
							})
						}
					})
					uni.setStorageSync('grade', this.grade);
					
					this.$forceUpdate();
				},300)
			},
			xuanzde(e) {
				//console.log(e)
				this.xuanz_moshi = e.name;
				this.operation = e.id
				this.close()
			},
			close() {
				this.$refs.popup.close()
			},
			change(e) {
				//console.log('当前模式：' + e.type + ',状态：' + e.show);
			},
			toggle(type) {
				// this.type = type
				// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
				this.$refs.popup.open(type)
			},
			banji() {
				var that = this

				// var data = {

				// 	page: that.page,
				// 	pageSize: that.pageSize,
				// }
				that.$post('grade/index').then(res => {
					if (res.code != 0) {
						that.grade = res.data
						// 后台返回的数组
						that.grade.forEach((item, index) => {
							// if(item.key) return
							Object.assign(item, {
								checked: false,
								select: 0
							})
						})
						console.log(`-----`,that.grade )
						uni.setStorageSync('grade', that.grade);
						that.shuaxinGrade();
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})

			},

			handleSelecteStudent(id, grade_id) {

				this.grade.forEach(item => {

					if (item.id == id) {
						//console.log(item.checked)

						if (item.checked == true) {
							var data = {
								isAllChecked: true
							}

							//console.log(456)
							uni.navigateTo({
								url: `/pages/student/index?id=${id}&isAllChecked=${data.isAllChecked}&grade_id=${grade_id}`,
							});
						} else {
							//console.log(12123)
							var data = {
								isAllChecked: false
							}

							uni.navigateTo({
								url: `/pages/student/index?id=${id}&isAllChecked=${data.isAllChecked}&grade_id=${grade_id}`,
							});
						}
					}
				})


				// uni.navigateTo({
				// 	url: `/pages/student/index?id=${id}`,
				// });
			},
			checkboxGradeChange(e,item,index) {
				var that = this
				var items = that.grade;
				that.alarms = []
				var values = e.detail.value;
				var valuesed = [item.id];
				console.log(values,"===")
				if (values.length != 0) {
					for (var i = 0, lenI = items.length; i < lenI; ++i) {
						items[i].checked = false;
						for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
							if (items[i].id == values[j]) {
								items[i].checked = true;
								break
							}
						}
					}

					items.forEach(item => {
						if (item.checked == true) {
							that.alarms.push(item);
							that.banjis(item.id, item.grade_id,item.checked)

						} else {
						}
					})
				} else {
					let gradeId = ""
					that.grade.forEach((itemss, index) => {
						console.log(valuesed[0],itemss.id,itemss,"===values == itemss.id");
						if(valuesed[0] == itemss.id){
							itemss.checked = false,
								itemss.select = 0;
							gradeId = itemss.grade_id;
						}
					})
					this.xuanzhede_bj.forEach((itemss, index) => {
						console.log(valuesed[0],itemss.id,"==valuesed[0] == itemss.id && gradeId == itemss.cid",valuesed[0] == itemss.id && gradeId == itemss.cid,gradeId,itemss.cid)
						if(valuesed[0] == itemss.id && gradeId == itemss.cid){
							this.xuanzhede_bj.splice(index,1)
						}
					})
					uni.setStorageSync('grade',this.grade)
					uni.setStorageSync('xuanzhede_bj',this.xuanzhede_bj)
					this.shuaxinGrade();
					// uni.removeStorage({
					// 	key: 'grade',
					// 	success: function() {
					// 		//console.log('清除成功');
					// 	},
					// 	fail: function() {
					// 		//console.log('清除失败');
					// 	}
					// })
					// uni.removeStorage({
					// 	key: 'xuanzhede_bj',
					// 	success: function() {
					// 		//console.log('清除成功');
					// 	},
					// 	fail: function() {
					// 		//console.log('清除失败');
					// 	}
					// })
					// //console.log(1111)
					// uni.setStorageSync('xuanzhede_bj', this.xuanzhede_bj);

					that.$forceUpdate();
				}




			},

			banjis(id, grade_id,check) {
				var that = this
				var checkedList = []
				var cjings = []
				var alarms = []

				var data = {
					id: id,
					page: that.page,
					pageSize: that.pageSize,
				}

				that.$get('grade/getStudent?id=' + data.id).then(res => {
					if (res.code != 0) {
						that.student = res.data
						// 后台返回的数组
						that.student.forEach((item, index) => {
							let itemVal = String(item.id)
							checkedList.push(itemVal);
						})
						if (check) {
							let sig = {
								'cid': grade_id,
								'id': id,
								'uid': checkedList
							}
							let existingItem = this.xuanzhede_bj.findIndex(items => items.id == id);
							if(existingItem!='-1'){
								this.xuanzhede_bj.splice(existingItem,1,sig);
							}else{
								this.xuanzhede_bj.push(sig)
							}
						}else{
							let existingItem = this.xuanzhede_bj.findIndex(items => items.id == id);
							if(existingItem!='-1'){
								this.xuanzhede_bj.splice(existingItem,1);
							}
						}
						uni.setStorageSync('xuanzhede_bj', this.xuanzhede_bj);
						this.shuaxinGrade();
						
						//console.log(that.student,'that.studentthat.studentthat.studentthat.studentthat.student班级id')
						// 后台返回的数组
						// that.student.forEach((item, index) => {
						// 	item.isChecked = true;
						// 	let itemVal = String(item.id)
						// 	checkedList.push(itemVal);
						// 	that.grade.forEach((items, index) => {
						// 		//console.log(item)
						// 		if (items.checked == true) {
						// 			if (items.grade_id == grade_id) {
						// 				items.select = checkedList.length
						// 				cjings.push(items) //这是计算获取班级几个学生
						// 				items.uid = checkedList
						// 				//console.log(checkedList, 'checkedList')
						// 			}
						// 		} else {
						// 			items.select = 0
						// 		}
						//
						// 	})
						// })

						// var sggsge = uni.getStorageSync('grade') || []; ///从本地缓存中同步移除指定key的数据
						//
						// //console.log(checkedList, '这是计算获取班级几个学生')
						// let alarmsgdsg = [...sggsge, ...cjings]
						// var ig = this.deduplicate(alarmsgdsg, 'id')
						// //console.log(ig, 'igigigig')
						// uni.setStorageSync('grade', ig);
						// var sdgg = uni.getStorageSync('grade') || []; ///从本地缓存中同步移除指定key的数据
						//
						// that.grade.forEach((item, index) => {
						// 	//console.log()
						// 	if (item.checked == true) {
						// 		sdgg.forEach((items, index) => {
						// 			if (items.id == item.id) {
						// 				item.select = items.select
						// 			}
						// 		})
						//
						// 	} else {
						// 		//console.log(111)
						// 		item.select = 0
						// 	}
						//
						// })

						//console.log(that.grade, 'that.alarmsthat.alarmsthat.alarms')

					

						// that.grade.forEach(item => {
						// 	//console.log(1212.333)
						// 	if (item.uid != undefined) {
						// 		let sig = {
						// 			'cid': item.id,
						// 			'uid': item.uid
						// 		}
						// 		alarms.push(sig);
						// 	}
						//
						//
						// })
										


						// uni.setStorageSync('xuanzhede_bj', alarms);


						this.$forceUpdate();

					} else {


						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}


				})

			},




			/** 数组去重
			 * 思路：利用数组原型对象上的 filter 和 includes 方法
			 * @param arr 需要去重的数组
			 * @param t 根据 t 字段(指定)进行去重
			 * @returns {*[]} 已去重后的数据
			 */
			deduplicate(arr, t = "") {
				let newArr = []
				// 有指定字段
				if (t) {
					newArr = arr.filter(function(item) {
						return newArr.includes(item[t]) ? "" : newArr.push(item[t])
					})
				}
				// 无指定字段
				else {
					newArr = arr.filter(function(item) {
						return newArr.includes(item) ? "" : newArr.push(item)
					})
				}
				return newArr
			},
			/** 数组去重结束**/
			handleSwitchWorkType(type) {
				//console.log(type)
				this.workType = type;
				if (type == 0) {
					this.typesf = 1
				}
				if (type == 1) {
					this.typesf = 2
				}
			},

			//截止时间后学生可补交

			checkboxAnswerChange_bujiao(e) {
				this.isAnswer_bujiao = e.target.value[0] ? true : false;
				if (this.isAnswer_bujiao == true) {
					this.repair = 1
				} else {
					this.repair = 0
				}
				//console.log("-change事件:", e.target.value);
			},

			// 学生提交可查看分数
			checkboxAnswerChange_fenshu(e) {
				this.isAnswer_fenshu = e.target.value[0] ? true : false;
				if (this.isAnswer_fenshu == true) {
					this.checkscore = 1
				} else {
					this.checkscore = 0
				}
				//console.log("-change事件:", e.target.value);
			},
			//学生不可查看分数答案(截止后也不可看)
			checkboxAnswerChange_bukeckfs(e) {
				this.isAnswer_bukeckfs = e.target.value[0] ? true : false;
				if (this.isAnswer_bukeckfs == true) {
					this.checksw = 1
				} else {
					this.checksw = 0
				}
				//console.log(this.checksw)
				//console.log("-change事件:", e.target.value);
			},
			// 查看详情
			checkboxDetailChange(e) {
				this.isDetail = e.target.value[0] ? true : false;
				if (this.isDetail == true) {
					this.checkinfo = 1
				} else {
					this.checkinfo = 0
				}
				//console.log("-change事件:", e.target.value);
			},
			// 查看答案
			checkboxAnswerChange(e) {
				this.isAnswer = e.target.value[0] ? true : false;

				if (this.isAnswer == true) {
					this.checkanswer = 1
				} else {
					this.checkanswer = 0
				}

				//console.log("-change事件:", e.target.value);
			},
			// 低于满分。。。勾选
			checkboxLimitChange(e) {
				this.isLimit = e.target.value[0] ? true : false;
				if (this.isLimit == true) {
					this.lowfullbi = 1
				} else {
					this.lowfullbi = 0
				}
				//console.log("-change事件:", e.target.value);
			},
			// 截止时间设置
			radioChange(e) {
				this.endTimeType = e.target.value;
				this.deadlinetime = getEndOfDayTimestamp(e.target.value);
			},
			// 定时布置
			checkboxChange(e) {
				this.dingshifabu = e.target.value[0] ? true : false;
				if (this.dingshifabu == true) {
					this.timing = 1
				} else {
					this.timing = 0
				}
				//console.log(this.timing)
				//console.log("-change事件:", e.target.value);
			},
			// 作业内容勾选
			checkboxWorkChange(e) {
				//console.log("-change事件:", e.target.value);
			},
			timestampToDateTime(timestamp) {
				const date = new Date(timestamp); // 将时间戳转换为Date对象
				const year = date.getFullYear(); // 获取年份
				const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 获取月份并补零
				const day = date.getDate().toString().padStart(2, '0'); // 获取日期并补零
				const hours = date.getHours().toString().padStart(2, '0'); // 获取小时并补零
				const minutes = date.getMinutes().toString().padStart(2, '0'); // 获取分钟并补零
				const seconds = date.getSeconds().toString().padStart(2, '0'); // 获取秒钟并补零
				
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // 拼接成标准日期时间格式
			},
			handleSubmitWork() {
				var dasf = []
				//console.log(this.workType)
				this.cidjson = uni.getStorageSync('xuanzhede_bj') || []; ///从本地缓存中同步移除指定key的数据
				// dasf.push(this.cidjson)
				this.ridjson = uni.getStorageSync('xuanzhede_ti') || []; ///从本地缓存中同步移除指定key的数据
				// JSON.stringify(bushi)

				// 示例使用
				// const timestamp = 1615182400000; // 假设这是你从选择器中得到的时间戳
				const endDateTime = this.timestampToDateTime(this.deadlinetime); // 转换为日期时间字符串
				const startDateTime = this.timestampToDateTime(this.startTime); // 转换为日期时间字符串
				//console.log(endDateTime,startDateTime); // 输出转换后的日期时间

				var data = {
					name: this.name,
					pid: this.ridjson.pid, //
					ptype: this.ptype,
					ridjson: this.ridjson,
					cidjson: this.cidjson,
					operation: this.operation,
					type: this.typesf,
					checkinfo: this.checkinfo,
					checkanswer: this.checkanswer,
					checkscore: this.checkscore,
					checksw: this.checksw,
					repair: this.repair,
					lowfullbi: this.lowfullbi,
					lowfullci: this.lowfullci,
					percentage: this.percentage,
					frequency: this.frequency,
					startTime:startDateTime,
					deadlinetime: endDateTime,
					timing: this.timing,
					message:this.message
				}
				//console.log(data)
				//console.log(this.xuanzhede_bj.length)
				if(this.cidjson.length!=0){
					this.$post('homework/add', data).then(res => {
						if (res.code != 0&&res.code != 403&&res.code==1) {
							uni.removeStorageSync('xuanzhede_bj');
							uni.removeStorageSync('xuanzhede_ti');
							uni.removeStorageSync('xuanzhede');
							uni.removeStorageSync('grade');
							// uni.removeStorageSync('grade');
							//console.log(res)
					
							uni.showToast({
								title: '发布成功',
								icon: 'none',
								duration: 2000
							});
							setTimeout(() => {
								this.openExternalURL();
								// uni.redirectTo({
								// 	url: '/pages/homework/index'
								// });
							}, 600);
					
					
						} else {
							uni.removeStorageSync('xuanzhede_bj');
							uni.removeStorageSync('xuanzhede_ti');
							uni.removeStorageSync('xuanzhede');
							uni.removeStorageSync('grade');
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						}
					
					
					})
				}else{
							uni.showToast({
								title: '请选择班级',
								icon: 'none',
								duration: 2000
							});
				}
				



			},
			openExternalURL() {
				window.location.href = 'learnteacher://opentabbar';
			},
		}
	}
</script>

<style>
	.content {
		padding: 0 32rpx 40rpx;
	}

	.module-name {
		overflow-wrap: break-word;
		color: rgba(102, 102, 102, 1);
		font-size: 26rpx;
		font-family: PingFangSC-Regular;
		font-weight: normal;
		white-space: nowrap;
		line-height: 36rpx;
		margin: 30rpx 0 20rpx 16rpx;
	}

	.module-wrapper {
		background-color: rgba(255, 255, 255, 1);
		border-radius: 24rpx;
		width: 686rpx;
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		justify-content: space-between;
		box-sizing: border-box;
	}

	.module-box {
		width: 100%;
		display: flex;
		box-sizing: border-box;
		padding: 40rpx 32rpx;
		position: relative;
		overflow: hidden;
	}

	.module-box::after {
		content: '';
		width: 622rpx;
		height: 2rpx;
		background-color: rgba(238, 238, 238, 1);
		position: absolute;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
	}

	.module-box:last-of-type::after {
		display: none;
	}

	.item-title {
		width: 112rpx;
		overflow-wrap: break-word;
		color: rgba(114, 122, 142, 1);
		font-size: 28rpx;
		font-family: PingFangSC-Regular;
		font-weight: normal;
		white-space: nowrap;
		//line-height: 40rpx;
		display: flex;
		align-items: center;
	}
	.item-titles{
		align-items: flex-start;
		padding-top: 6rpx;
	}
	.item-titles1{
		align-items: flex-start;
	}
	.item-box {
		flex: 1;
		display: flex;
		align-items: center;
		margin-left: 24rpx;
	}

	.item-box2 {
		flex: 1;
		margin-left: 32rpx;
	}

	.item-box2 .item-name {
		position: relative;
	}

	.item-box2 .item-name::after {
		content: '';
		width: 10rpx;
		height: 18rpx;
		background-image: url(@/static/arrow_icon.png);
		position: absolute;
		top: 50%;
		right: 0;
		transform: translateY(-50%);
	}

	.item-desc {
		color: rgba(153, 153, 153, 1);
		font-size: 24rpx;
		margin-bottom: 32rpx;
	}

	.item-condition .item-name {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.item-option {
		display: flex;
		margin-bottom: 32rpx;
	}

	.item-option:last-child {
		margin-bottom: 0;
	}

	.grade-item {
		display: flex;
		align-items: center;
		margin-bottom: 32rpx;
		position: relative;
	}

	.uni-label-pointer:last-of-type .grade-item {
		margin-bottom: 0;
	}

	.check-wrapper {
		width: 100%;
	}

	.check-box {
		margin-right: 30rpx;
	}

	.item-name {
		overflow-wrap: break-word;
		color: rgba(34, 34, 34, 1);
		font-size: 28rpx;
		font-family: PingFangSC-Regular;
		font-weight: normal;
		white-space: nowrap;
		line-height: 40rpx;
	}

	.grade-item::after {
		content: '';
		width: 10rpx;
		height: 18rpx;
		background-image: url(@/static/arrow_icon.png);
		position: absolute;
		top: 50%;
		right: 0;
		transform: translateY(-50%);
	}

	.limit-input {
		width: 54rpx;
		height: 32rx;
		border-radius: 6rpx;
		border: 2rpx solid rgba(41, 121, 255, 1);
		text-align: center;
		margin: 0 12rpx;
	}

	.submit-button {
		box-shadow: 0 8rpx 12rpx 0 rgba(41, 121, 255, 0.5);
		background-color: rgba(41, 121, 255, 1);
		border-radius: 44rpx;
		height: 88rpx;
		width: 686rpx;
		margin: 80rpx 0 0 0;

		color: rgba(255, 255, 255, 1);
		font-size: 28rpx;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		white-space: nowrap;
		line-height: 88rpx;
		text-align: center;
	}
	
	.submit-buttons {
		margin: 0 auto;
		/* box-shadow: 0 8rpx 12rpx 0 rgba(41, 121, 255, 0.5); */
		border: 1rpx solid rgba(41, 121, 255, 0.5);
		background-color: #fff;
		border-radius: 44rpx;
		height: 88rpx;
		width: 80%;
		margin: 25px auto;
		/* margin: 50rpx 0 0 0; */
	color: #297AFF;
		/* color: rgba(255, 255, 255, 1); */
		font-size: 28rpx;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		white-space: nowrap;
		line-height: 88rpx;
		text-align: center;
	}

	.radio-group {
		display: flex;
	}

	.item-tags {
		display: flex;
		margin-top: 12rpx;
		margin-bottom: 16rpx;
	}

	.tag-text {
		background-color: #FFFFFF;
		border-radius: 4rpx;
		height: 32rpx;
		width: 68rpx;
		color: rgba(41, 121, 255, 1);
		font-size: 22rpx;
		font-family: PingFangSC-Regular;
		font-weight: normal;
		text-align: center;
		white-space: nowrap;
		line-height: 32rpx;
		margin-left: 12rpx;
		border: 1rpx solid rgba(41, 121, 255, 1);
	}

	.selectedWork {
		color: rgba(255, 255, 255, 1);
		background-color: rgba(41, 121, 255, 1);
	}

	.uni-list-cell {
		display: flex;
	}

	.uni-list-cell:last-child {
		margin-left: 30rpx;
	}
	.zuoyeneirong{
		position: relative;
		display: flex;
		.item-title{
			margin-right: 24rpx;
		}
		&::after {
			content: '';
			width: 311px;
			height: 1px;
			background-color: rgba(238, 238, 238, 1);
			position: absolute;
			bottom: -20px;
			left: 50%;
			-webkit-transform: translateX(-50%);
			transform: translateX(-50%);
		}
	}
</style>